package com.centaline.androidsalesblog.rx.database;

import com.centaline.androidsalesblog.constants.AppConstant;
import com.centaline.androidsalesblog.model.databaseobject.CityCenterDo;

import org.litepal.crud.DataSupport;

import java.util.List;

import rx.Observable;
import rx.Subscriber;

/**
 * 获取当前城市信息(经纬度)
 * Created by guilin on 16/2/15.
 */
final class CityCenterOnSubscribe implements Observable.OnSubscribe<CityCenterDo> {

    @Override
    public void call(Subscriber<? super CityCenterDo> subscriber) {
        final List<CityCenterDo> cityCenterDos = DataSupport
                .where("cityCode = ?", AppConstant.CityCode)
                .find(CityCenterDo.class);
        if (!subscriber.isUnsubscribed() &&
                cityCenterDos.size() > 0) {
            subscriber.onNext(cityCenterDos.get(0));
        }
        subscriber.onCompleted();
    }
}
